<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            
        }

        #canvas {
            margin: auto;
            display: block;
            box-shadow: 0 5px 5px rgba(0, 0, 0, .5);
            background-color: yellow;
        }
    </style>
</head>

<body>
    <canvas id="canvas">
    </canvas>


    <script>
        var canvas = document.querySelector("#canvas");
        var WIDTH = 500,
            HEIGHT = 500;

        canvas.width = WIDTH;
        canvas.height = HEIGHT;
        var ctx = canvas.getContext('2d');

        for (var i = 0; i < 10; i++) {
            ctx.beginPath();
            ctx.moveTo(0, 50 + 50 * i)
            ctx.lineTo(500, 50 + 50 * i)
            ctx.strokeStyle = 'black'
            ctx.lineWidth = 1
            ctx.stroke()

        }
        for (var i = 0; i < 10; i++) {
            ctx.beginPath();
            ctx.moveTo(50 + 50 * i, 0)
            ctx.lineTo(50 + 50 * i, 500)
            ctx.strokeStyle = 'black'
            ctx.lineWidth = 1
            ctx.stroke()

        }

        var Yes = false;
        canvas.onclick = function () {
            if (Yes) {
                canvas.onmousedown = function (e) {
                    ctx.fillStyle = 'black';
                    ctx.beginPath();
                    ctx.arc(Math.round(e.offsetX / 50) * 50, Math.round(e.offsetY / 50) * 50, 20, 0, 2 * Math
                        .PI);
                    ctx.fill();
                }
            } else {
                canvas.onmousedown = function (e) {
                    ctx.fillStyle = 'white';
                    ctx.beginPath();
                    ctx.arc(Math.round(e.offsetX / 50) * 50, Math.round(e.offsetY / 50) * 50, 20, 0, 2 * Math
                        .PI);
                    ctx.fill();
                }
            }
            Yes = !Yes;
        }
    </script>

</body>

</html>